package com.fearless.controller;

import com.fearless.crm.settings.entity.Person;
import com.fearless.crm.settings.service.PersonService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//处理器类
@Controller
@RequestMapping("mybatis")
public class MyController {

    @Resource
    private PersonService service;

    //这里我们来复习json
    @RequestMapping("/review")
    @ResponseBody
    public List<Person> reviewMybatis(){
        System.out.println("处理器方法执行开始");
        List list=service.selectAll();
        System.out.println("处理器方法执行结束");
        return list;
    }

    @RequestMapping("/register")
    @ResponseBody
    public Map<String,Object> doRegister(Integer id,String name,String email,Integer age){
        System.out.println("进入到注册处理器方法");
        Person person=new Person();
        person.setId(id);
        person.setName(name);
        person.setEmail(email);
        person.setAge(age);
        Map map=new HashMap();
        int num=service.addPersonService(person);

        if(num!=1){
            map.put("flag",false);
        }else {

            map.put("flag",true);
        }
        return map;
    }
}
